package com.ssy.lingxi.product.repository.customer;

import com.ssy.lingxi.product.entity.customer.CustomerCategory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * 品类持久化层
 * @author jw.chen
 * @version 2.0.0
 * @date 2020/6/22
 */
public interface CustomerCategoryRepository extends JpaRepository<CustomerCategory,Long>, JpaSpecificationExecutor<CustomerCategory> {
    @Query("select max(cc.level) from CustomerCategory cc where cc.memberId = ?1")
    Integer findMaxLevelByMemberId(Long memberId);

    Page<CustomerCategory> findByMemberIdAndMemberRoleIdAndNameContainingOrderByIdDesc(Long memberId, Long memberRoleId, String name, Pageable page);

    List<CustomerCategory> findByMemberIdAndMemberRoleIdAndNameContainingOrderByIdDesc(Long memberId, Long memberRoleId, String name);

    Page<CustomerCategory> findByMemberIdAndMemberRoleIdOrderByIdDesc(Long memberId, Long memberRoleId, Pageable page);

    List<CustomerCategory> findByMemberIdAndMemberRoleIdOrderByIdDesc(Long memberId, Long memberRoleId);

    List<CustomerCategory> findByMemberIdAndMemberRoleIdAndLevelAndParentIdAndNameAndIdNot(Long memberId, Long memberRoleId, Integer level, Long parentId, String name, Long id);

    List<CustomerCategory> findByMemberIdAndMemberRoleIdInAndLevelAndParentIdAndNameAndIdNot(Long memberId, List<Long> memberRoleIds, Integer level, Long parentId, String name, Long id);

    List<CustomerCategory> findByMemberIdAndMemberRoleIdAndParentId(Long memberId, Long memberRoleId, Long parentId);

    List<CustomerCategory> findByMemberIdAndMemberRoleIdAndFullIdStartingWith(Long memberId, Long memberRoleId, String parentId);

    List<CustomerCategory> findByFullIdLike(String categoryId);

    List<CustomerCategory> findByMemberIdAndMemberRoleIdAndLevelAndName(Long memberId, Long memberRoleId, Integer level, String name);

    List<CustomerCategory> findByMemberIdAndMemberRoleId(Long memberId, Long memberRoleId);

    List<CustomerCategory> findByMemberIdAndMemberRoleIdOrderByFullId(Long memberId, Long memberRoleId);

    List<CustomerCategory> findByMemberIdIn(List<Long> memberIdList);

    List<CustomerCategory> findByMemberIdInAndMemberRoleIdIn(List<Long> memberIdList, List<Long> memberRoleIdList);

    List<CustomerCategory> findByCustomerAttributeListId(Long attributeId);

    //平台后台调用
    List<CustomerCategory> findByCategoryId(Long categoryId);

    List<CustomerCategory>  findByMemberIdAndMemberRoleIdAndNameIn(Long memberId, Long memberRoleId, List<String> categoryNameList);

}
